﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Xml.Serialization;

namespace AgileDashboard.Entities
{
    public class UserStory : WorkItem
    {


        private double? _storyPoints;

        
        Dictionary<string, double> StoryPointSummary = new Dictionary<string, double>();

        [NotMapped]
        [XmlIgnore]
        public double? StoryPoints
        {
            get 
            {
                if (this.IsEPIC)
                    return CalculateEpicStoryPoints();
                
                return _storyPoints; 
            
            }
            set { _storyPoints = value; }
        }
        


        public double CalculateEpicStoryPoints()
        {
            


            double storyPoints = 0;

            if (this.LinkedWorkedItems == null)
                return 0;

            foreach (UserStory us in this.LinkedWorkedItems)
            {
                if (us.StoryPoints.HasValue)
                    storyPoints += us.StoryPoints.Value;

            }

            return storyPoints;

        }

        [NotMapped]
        public bool IsEPIC
        {
            get
            {
                return Title.ToLower().Contains("epic");
            }

        }






    }
}
